<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="响应编码" prop="code">
        <el-input
          v-model="queryParams.code"
          placeholder="请输入响应编码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="响应信息" prop="message">
        <el-input
          v-model="queryParams.message"
          placeholder="请输入响应信息"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="流程编号" prop="processCode">
        <el-input
          v-model="queryParams.processCode"
          placeholder="请输入流程编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="姓名" prop="candidateName">
        <el-input
          v-model="queryParams.candidateName"
          placeholder="请输入姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="性别" prop="sex">
        <el-select v-model="queryParams.sex" placeholder="请选择性别" clearable size="small">
          <el-option
            v-for="dict in sexOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="学校" prop="school">
        <el-input
          v-model="queryParams.school"
          placeholder="请输入学校"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="专业" prop="profession">
        <el-input
          v-model="queryParams.profession"
          placeholder="请输入专业"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="毕业时间" prop="graduateDate">
        <el-date-picker clearable size="small" style="width: 200px"
          v-model="queryParams.graduateDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择毕业时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="可入职时间" prop="entryDate">
        <el-date-picker clearable size="small" style="width: 200px"
          v-model="queryParams.entryDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择可入职时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="身份证号" prop="idCard">
        <el-input
          v-model="queryParams.idCard"
          placeholder="请输入身份证号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系方式" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入联系方式"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="岗位名称" prop="personWork">
        <el-input
          v-model="queryParams.personWork"
          placeholder="请输入岗位名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="供应商名称" prop="pravidorName">
        <el-input
          v-model="queryParams.pravidorName"
          placeholder="请输入供应商名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="合同性质" prop="contractNature">
        <el-input
          v-model="queryParams.contractNature"
          placeholder="请输入合同性质"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否离职 Y N" prop="isLeave">
        <el-input
          v-model="queryParams.isLeave"
          placeholder="请输入是否离职 Y N"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="报价" prop="price">
        <el-input
          v-model="queryParams.price"
          placeholder="请输入报价"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="文件名称" prop="fileName">
        <el-input
          v-model="queryParams.fileName"
          placeholder="请输入文件名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:info:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:info:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:info:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:info:export']"
        >导出</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="infoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="响应编码" align="center" prop="code" />
      <el-table-column label="响应信息" align="center" prop="message" />
      <el-table-column label="流程编号" align="center" prop="processCode" />
      <el-table-column label="姓名" align="center" prop="candidateName" />
      <el-table-column label="性别" align="center" prop="sex" :formatter="sexFormat" />
      <el-table-column label="学校" align="center" prop="school" />
      <el-table-column label="学历" align="center" prop="eduBackground" />
      <el-table-column label="专业" align="center" prop="profession" />
      <el-table-column label="毕业时间" align="center" prop="graduateDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.graduateDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="可入职时间" align="center" prop="entryDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.entryDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="身份证号" align="center" prop="idCard" />
      <el-table-column label="联系方式" align="center" prop="phone" />
      <el-table-column label="岗位名称" align="center" prop="personWork" />
      <el-table-column label="供应商名称" align="center" prop="pravidorName" />
      <el-table-column label="合同性质" align="center" prop="contractNature" />
      <el-table-column label="是否离职 Y N" align="center" prop="isLeave" />
      <el-table-column label="报价" align="center" prop="price" />
      <el-table-column label="文件名称" align="center" prop="fileName" />
      <el-table-column label="简历名称" align="center" prop="pathName" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:info:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:info:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改候选人信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body :close-on-click-modal='false'>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="响应编码" prop="code">
          <el-input v-model="form.code" placeholder="请输入响应编码" />
        </el-form-item>
        <el-form-item label="响应信息" prop="message">
          <el-input v-model="form.message" placeholder="请输入响应信息" />
        </el-form-item>
        <el-form-item label="流程编号" prop="processCode">
          <el-input v-model="form.processCode" placeholder="请输入流程编号" />
        </el-form-item>
        <el-form-item label="姓名" prop="candidateName">
          <el-input v-model="form.candidateName" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="性别">
          <el-select v-model="form.sex" placeholder="请选择性别">
            <el-option
              v-for="dict in sexOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="学校" prop="school">
          <el-input v-model="form.school" placeholder="请输入学校" />
        </el-form-item>
        <el-form-item label="专业" prop="profession">
          <el-input v-model="form.profession" placeholder="请输入专业" />
        </el-form-item>
        <el-form-item label="学历" prop="eduBackground">
          <el-input v-model="form.eduBackground" placeholder="请输入学历" />
        </el-form-item>
        <el-form-item label="毕业时间" prop="graduateDate">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.graduateDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择毕业时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="可入职时间" prop="entryDate">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.entryDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择可入职时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="身份证号" prop="idCard">
          <el-input v-model="form.idCard" placeholder="请输入身份证号" />
        </el-form-item>
        <el-form-item label="联系方式" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入联系方式" />
        </el-form-item>
        <el-form-item label="岗位名称" prop="personWork">
          <el-input v-model="form.personWork" placeholder="请输入岗位名称" />
        </el-form-item>
        <el-form-item label="供应商名称" prop="pravidorName">
          <el-input v-model="form.pravidorName" placeholder="请输入供应商名称" />
        </el-form-item>
        <el-form-item label="合同性质" prop="contractNature">
          <el-input v-model="form.contractNature" placeholder="请输入合同性质" />
        </el-form-item>
        <el-form-item label="是否离职 Y N" prop="isLeave">
          <el-input v-model="form.isLeave" placeholder="请输入是否离职 Y N" />
        </el-form-item>
        <el-form-item label="报价" prop="price">
          <el-input v-model="form.price" placeholder="请输入报价" />
        </el-form-item>
        <el-form-item label="文件名称" prop="fileName">
          <el-input v-model="form.fileName" placeholder="请输入文件名称" />
        </el-form-item>
        <el-form-item label="简历名称" prop="pathName">
          <el-input v-model="form.pathName" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listInfo, getInfo, delInfo, addInfo, updateInfo } from "@/api/system/info";

export default {
  name: "Info",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 候选人信息表格数据
      infoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 性别字典
      sexOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        code: undefined,
        message: undefined,
        processCode: undefined,
        candidateName: undefined,
        sex: undefined,
        school: undefined,
        eduBackground: undefined,
        profession: undefined,
        graduateDate: undefined,
        entryDate: undefined,
        idCard: undefined,
        phone: undefined,
        personWork: undefined,
        pravidorName: undefined,
        contractNature: undefined,
        isLeave: undefined,
        price: undefined,
        fileName: undefined,
        pathName: undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        processCode: [
          { required: true, message: "流程编号不能为空", trigger: "blur" }
        ],
        candidateName: [
          { required: true, message: "姓名不能为空", trigger: "blur" }
        ],
        sex: [
          { required: true, message: "性别（1男 2女 ）不能为空", trigger: "blur" }
        ],
        school: [
          { required: true, message: "学校不能为空", trigger: "blur" }
        ],
        eduBackground: [
          { required: true, message: "学历不能为空", trigger: "blur" }
        ],
        profession: [
          { required: true, message: "专业不能为空", trigger: "blur" }
        ],
        graduateDate: [
          { required: true, message: "毕业时间不能为空", trigger: "blur" }
        ],
        entryDate: [
          { required: true, message: "可入职时间不能为空", trigger: "blur" }
        ],
        phone: [
          { required: true, message: "联系方式不能为空", trigger: "blur" }
        ],
        personWork: [
          { required: true, message: "岗位名称不能为空", trigger: "blur" }
        ],
        pravidorName: [
          { required: true, message: "供应商名称不能为空", trigger: "blur" }
        ],
        contractNature: [
          { required: true, message: "合同性质不能为空", trigger: "blur" }
        ],
        isLeave: [
          { required: true, message: "是否离职 Y N不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
    this.getDicts("oa_sex").then(response => {
      this.sexOptions = response.data;
    });
  },
  methods: {
    /** 查询候选人信息列表 */
    getList() {
      this.loading = true;
      listInfo(this.queryParams).then(response => {
        this.infoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 性别字典翻译
    sexFormat(row, column) {
      return this.selectDictLabel(this.sexOptions, row.sex);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        code: undefined,
        message: undefined,
        processCode: undefined,
        candidateName: undefined,
        sex: undefined,
        school: undefined,
        eduBackground:undefined,
        profession: undefined,
        graduateDate: undefined,
        entryDate: undefined,
        idCard: undefined,
        phone: undefined,
        personWork: undefined,
        pravidorName: undefined,
        contractNature: undefined,
        isLeave: undefined,
        price: undefined,
        fileName: undefined,
        pathName: undefined,
        remark: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加候选人信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getInfo(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改候选人信息";
      });
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != undefined) {
            updateInfo(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }
            });
          } else {
            addInfo(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除候选人信息编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delInfo(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/info/export', {
        ...this.queryParams
      }, `system_info.xlsx`)
    }
  }
};
</script>